package com.cangxuan.backend.controller;

import com.cangxuan.backend.annotation.Check;
import com.cangxuan.backend.entity.UserAmountRecord;
import com.cangxuan.backend.service.IBillService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Author: 彭伟辰
 * 流水控制器
 */

@Api(tags = "账单相关接口")
@RestController
@RequestMapping("bills")
public class BillController extends BaseController{
    IBillService billService;

    @Autowired
    public void setBillService(IBillService billService) {
        this.billService = billService;
    }
    /**
     * 账单参数
     */
    @Data
    @ApiModel("账单参数实体")
    public static class billBody{
        @ApiModelProperty("年份")
        String year;
        @ApiModelProperty("月份")
        String month;
        @ApiModelProperty("状态")
        Integer state;
    }
    @PostMapping("list")
    @ApiOperation("显示账单")
    public Object changeNickname(@Check @RequestBody billBody billBody) {
        List<UserAmountRecord> billList = billService.selectWhole(billBody.getYear(), billBody.getMonth(),billBody.getState());
        return success(billList);
    }
    @PostMapping("sumRevenue")
    @ApiOperation("查询收入总额")
    public Object sumRevenue(@Check @RequestBody billBody billBody) {
        return success(billService.selectTotal(billBody.getYear(),billBody.getMonth(),(byte)1));
    }
    @PostMapping("sumExpenditure")
    @ApiOperation("查询支出总额")
    public Object sumExpenditure(@Check @RequestBody billBody billBody) {
        return success(billService.selectTotal(billBody.getYear(),billBody.getMonth(),(byte)0));
    }
}
